<?php
/**
 * Created by PhpStorm.
 * User: aDaddy
 * Date: 2016/7/25
 * Time: 9:55
 */

namespace App\Model;

use App\Base\BaseModel;
use App\Base\IRI;
use App\Entity\MessageCategory;
use App\Model\Common\MessageCategoryCommonModel;
use Doctrine\Bundle\DoctrineBundle\Registry;
use App\Setting\MessageCategorySetting;
use Symfony\Component\HttpFoundation\Request;

class MessageCategoryModel extends BaseModel{


    /*
    * 列表基本设置【通用模块必须】
    */
    public function listSettingDefault()
    {
        $settings = new MessageCategorySetting($this->getDoctrine());
        return $settings->listConfig();
    }

    //获取所有分类
    public function getAllMessageCategory(){
        return $this->getRep()->findAll();
    }


    public function getSons4Setting($Cat=null)
    {

        $data = $this->getAllMessageCategory();
        $return=[];
        foreach ($data as $row) {
            if (!$Cat) {
                $return[ IRI::createIRIStringFromEntity(MessageCategory::class,$row->getId())] =  $row->getName();
            }else{
                if ($row->getCat() && $row->getCat()->getId() == $Cat) {
                    $return[ IRI::createIRIStringFromEntity(MessageCategory::class,$row->getId())] = $row->getName();
                }
            }
        }
        return $return ;
    }

    /*
     * 通用Rep
     */
    public function getRep()
    {
        $settings = new MessageCategorySetting($this->getDoctrine());
        return $this->em->getRepository($settings->bundleName.":".$settings->entityName);
    }

}